import 'package:flutter/material.dart';
import 'package:mall/constant/app_colors.dart';
import 'package:mall/constant/app_dimens.dart';
import 'package:mall/constant/app_strings.dart';
import 'package:mall/constant/text_style.dart';
import 'package:mall/modules/model/home_entity.dart';
import 'package:mall/ui/widgets/cached_image.dart';
import 'package:mall/router/navigator_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class TabHomeSpecial extends StatelessWidget {
  final List<HomeModelTopiclist> projectSelections;
  final String title;

  TabHomeSpecial(this.title, this.projectSelections);

  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 15, right: 15),
      child: Column(
        children: [
          Container(
            width: double.infinity,
            height: 45,
            alignment: Alignment.centerLeft,
            child: Text(
              title,
              style: TextStyle(
                  fontSize: ScreenUtil().setSp(AppDimens.DIMENS_56),
                  color: AppColors.C_333333,
                  fontWeight: FontWeight.w600),
            ),
          ),
          ListView.builder(
              physics: NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              padding: EdgeInsets.all(0),
              itemCount: projectSelections.length,
              itemBuilder: (BuildContext context, int index) {
                return _itemView(context, projectSelections[index]);
              }),
        ],
      ),
    );
  }

  Widget _itemView(BuildContext context, HomeModelTopiclist projectSelections) {
    return Container(
      child: Card(
        child: InkWell(
          onTap: () => _goDetail(context, projectSelections.id),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                child: CachedImageView(
                    double.infinity, ScreenUtil().setHeight(AppDimens.DIMENS_400), projectSelections.picUrl),
              ),
              Padding(padding: EdgeInsets.only(top: 10)),
              Container(
                  padding: EdgeInsets.only(left: 10),
                  child: Text(projectSelections.title ?? "",
                      maxLines: 1, overflow: TextOverflow.ellipsis, style: FMTextStyle.color_222222_size_13)),
              Padding(padding: EdgeInsets.only(top: 10)),
              Container(
                  padding: EdgeInsets.only(left: 10),
                  child: Text(projectSelections.subtitle ?? "",
                      maxLines: 1, overflow: TextOverflow.ellipsis, style: FMTextStyle.color_999999_size_12)),
              Padding(padding: EdgeInsets.only(top: 10)),
              Container(
                  padding: EdgeInsets.only(left: 10, bottom: 10),
                  child:
                      Text(AppStrings.DOLLAR + "${projectSelections.price}", style: FMTextStyle.color_ff5722_size_12)),
            ],
          ),
        ),
      ),
    );
  }

  _goDetail(BuildContext context, int? id) {
    NavigatorUtil.goProjectSelectionDetailView(context, id);
  }
}
